package com.rayc.mall.item.controller;

import com.rayc.mall.api.dto.ItemDTO;
import com.rayc.mall.api.dto.OrderItemDTO;
import com.rayc.mall.common.result.Result;
import com.rayc.mall.item.service.IItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

/**
 * @Author: Ray-C
 * @CreateTime: 2025-03-26
 * @Description: item操作controller
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/items")
public class ItemController {
    @Resource
    private IItemService itemService;

    // feign interface
    @GetMapping("/list")
    public Result<List<ItemDTO>> queryByIds(@RequestParam Set<Long> ids) {
        log.info("根据id批量查询商品 ids: {}", ids);
        List<ItemDTO> items = itemService.queryItemByIds(ids);
        log.info("批量查询到商品 items: {}", items);
        return Result.success(items);
    }

    // feign interface
    @PostMapping("/updateStockAndSold")
    Result<String> updateStockAndSold(List<OrderItemDTO> items) {
        log.info("更新库存和销量信息 items: {}", items);
        itemService.updateStockAndSold(items);
        log.info("更新库存和销量信息成功 items: {}", items);
        return Result.success();
    }
}
